<template>
	<view>
		<view>
			<u-tabbar
				:value="value1"
				@change="change1"
			>
				<u-tabbar-item 
					v-for="(item,index) in menus" 
					:text="item.text" 
					:icon="item.icon"></u-tabbar-item>
			</u-tabbar>
		</view>
	</view>
</template>

<script>
	export default {
		name:"hyx-tabbar",
		props: {
			
		},
		data() {
			return {
				value1: 0,
				menus: []
			};
		},
		created() {
			console.log("打开页面")
			this.menusInit();
		},
		methods: {
			menusInit() {
				uni.getStorage({
					key: this.$constant.TAB_INDEX,
					success: (res) => {
						this.value1 = res.data;
					}
				})
				//报价师角色-菜单
				const roleQuoter = [
					{text: '工作台', icon:"home", url: '/pages/quoter/index'},
					{text: '统计', icon:"photo", url: '/pages/quoter/statistics'},
					{text: '订单', icon:"play-right", url: '/pages/quoter/order'},
					{text: '我的', icon:"account", url: '/pages/quoter/personal'}
				]
				//回收端管理员-菜单
				const roleAdmin = [
					{text: '工作台', icon:"home", url: "/pages/admin/index"},
					{text: '统计', icon:"photo", url: "/pages/admin/statistics"},
					{text: '我的', icon:"account", url: "/pages/admin/personal"}
				]
				
				uni.getStorage({
					key: this.$constant.ROLE_INFO_KEY,
					success: (res) => {
						if(res.data.role === 'admin'){
							this.menus = roleAdmin
						}else {
							this.menus = roleQuoter
						}
					}
				})
			},
			change1(e) {
				this.value1 = e;
				uni.setStorage({
					key:this.$constant.TAB_INDEX,
					data: e
				})
				uni.redirectTo({
					url: this.menus[e].url
				})
			}
		}
	}
</script>

<style>
	
	.tabbar-box {
		position: absolute;
		background-color: #fff;
		width: 100%;
		height: 150rpx;
		bottom: 0;
		margin: -2% !important;
		border-top: solid 1px #b4b3b1;
	}
</style>